package com.ruoyi.LXHappointment.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.LXHappointment.mapper.LXHAppointmentMapper;
import com.ruoyi.LXHappointment.domain.LXHAppointment;
import com.ruoyi.LXHappointment.service.ILXHAppointmentService;

/**
 * 个人预约就诊Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-18
 */
@Service
public class LXHAppointmentServiceImpl implements ILXHAppointmentService 
{
    @Autowired
    private LXHAppointmentMapper lXHAppointmentMapper;


    /**
     * 查询个人预约就诊
     * 
     * @param appId 个人预约就诊主键
     * @return 个人预约就诊
     */
    @Override
    public LXHAppointment selectLXHAppointmentByAppId(Long appId)
    {
        return lXHAppointmentMapper.selectLXHAppointmentByAppId(appId);
    }

    /**
     * 查询个人预约就诊列表
     * 
     * @param lXHAppointment 个人预约就诊
     * @return 个人预约就诊
     */
  @Override
public List<LXHAppointment> selectLXHAppointmentList(LXHAppointment lXHAppointment)
{
    // 强制设置为当前登录用户的预约（无论前端传什么，都只能查自己的）
    lXHAppointment.setUserId(SecurityUtils.getUserId());
    return lXHAppointmentMapper.selectLXHAppointmentList(lXHAppointment);
}

    /**
     * 新增个人预约就诊
     * 
     * @param lXHAppointment 个人预约就诊
     * @return 结果
     */
@Override
public int insertLXHAppointment(LXHAppointment lXHAppointment)
{
    // 获取当前登录用户的 ID
    Long currentUserId = SecurityUtils.getUserId();

    // 添加到预约对象中
    lXHAppointment.setUserId(currentUserId);

    // 设置创建时间为当前时间
    lXHAppointment.setAppCreate(new Date());

     lXHAppointmentMapper.insertLXHAppointment(lXHAppointment);

    Long generatedAppId = lXHAppointment.getAppId();



    return lXHAppointmentMapper.insertLXHTreatment(generatedAppId);
}


    /**
     * 修改个人预约就诊
     * 
     * @param lXHAppointment 个人预约就诊
     * @return 结果
     */
    @Override
    public int updateLXHAppointment(LXHAppointment lXHAppointment)
    {
        return lXHAppointmentMapper.updateLXHAppointment(lXHAppointment);
    }

    /**
     * 批量删除个人预约就诊
     * 
     * @param appIds 需要删除的个人预约就诊主键
     * @return 结果
     */
    @Override
    public int deleteLXHAppointmentByAppIds(Long[] appIds)
    {
        return lXHAppointmentMapper.deleteLXHAppointmentByAppIds(appIds);
    }

    /**
     * 删除个人预约就诊信息
     * 
     * @param appId 个人预约就诊主键
     * @return 结果
     */
    @Override
    public int deleteLXHAppointmentByAppId(Long appId)
    {
        return lXHAppointmentMapper.deleteLXHAppointmentByAppId(appId);
    }
}
